<script>
	import Vue from 'vue'



	export default {
		globalData: {

			// #ifdef MP-TOUTIAO


			videoAd: tt.createRewardedVideoAd({
				adUnitId: 'hcvhsvah3oi5j9xhru', //2024年7月14日 更新
			}),
			currentPage: Object,

			playAd: function() {
				// 官方API
				const videoAd = tt.createRewardedVideoAd({
					adUnitId: 'hcvhsvah3oi5j9xhru',
				})
				videoAd
					.show()
					.then(() => {
						console.log("广告显示成功");
					})
					.catch((err) => {
						console.log("广告组件出现问题", err);
						// 可以手动加载一次
						videoAd.load().then(() => {
							console.log("手动加载成功");
							// 加载成功后需要再显示广告
							return videoAd.show();
						});
					});
			},

			// 显示插屏广告(抖音)
			ttChaping(ttAdId = 'lpnfmw23ll2e1tawkj') {
				// #ifdef MP-TOUTIAO
				console.info('插屏广告id是:', ttAdId);
				// 查看排行榜插屏 2024年9月3日 更新
				const interstitialAd = tt.createInterstitialAd({
					adUnitId: ttAdId,
				});
				console.info("显示插屏广告");
				interstitialAd
					.load()
					.then(() => {
						interstitialAd.show();
					})
					.catch((err) => {
						console.log(err);
					});

				// #endif
			},

			// #endif

		},
		onLaunch: function({
			query
		}) {
			console.log('App Launch')
			if (this.globalData.videoAd) {
				// onClose只监听一次
				this.globalData.videoAd.onClose(res => {
					if (res.isEnded) {
						// 实现子子页面的closeAdFunction与cancelAdFunction方法
						this.globalData.currentPage.closeAdFunction()
					} else {
						this.globalData.currentPage.cancelAdFunction()
					}
				})
			}
			if (query.spread) {
				uni.setStorage({
					key: 'spread',
					data: query.spread
				})
			}

			uni.getSystemInfo({
				success: function(e) {
					// #ifndef MP
					Vue.prototype.StatusBar = e.statusBarHeight;
					if (e.platform == 'android') {
						Vue.prototype.CustomBar = e.statusBarHeight + 50;
					} else {
						Vue.prototype.CustomBar = e.statusBarHeight + 45;
					};
					// #endif

					// #ifdef MP-WEIXIN
					Vue.prototype.StatusBar = e.statusBarHeight;
					let custom = wx.getMenuButtonBoundingClientRect();
					Vue.prototype.Custom = custom;
					Vue.prototype.CustomBar = custom.bottom + custom.top - e.statusBarHeight + 4;
					// #endif		

					// #ifdef MP-ALIPAY
					Vue.prototype.StatusBar = e.statusBarHeight;
					Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight;
					// #endif
				}
			});

		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>

<style>
	/*每个页面公共css */
	.gold {
		width: 20px;
		height: 20px;
	}
</style>